<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
//查询学生请求
$(document).ready(function(){
	var endPage=0;//结束的页数
	var pageNum=1;//当前页数
	var pageSize=2;//每页显示条数
	
	function findStudentInfo() {
		var sid=$("#fid").val();
		var className=$("#fclassName").val();
		var sname=$("#fsname").val();
		$.ajax({
			url: "/Student/findStudentByNamesId",
			data:{id:$("#fid").val(),name:$("#fsname").val(),className:$("#fclassName").val(),pageNum:pageNum,pageSize:pageSize},
			type: "get",
			dataType: "json",
			success: function(data) {
				
				var list= data.list;
				console.log(data);
				

				//每次进来先清空
				$("#tr1").siblings().remove();
				//取值
				endPage=data.pages;//结束的页数大小
				
				$.each(list,function(index,data){
					//判断0或1 数据库存0/1
					var sex="男";
					if(data.sex==0){
						sex="女";
					}
					$("<tr id=tr"+index+"><td>"+data.id+"</td>"+
							  "<td>"+data.name+"</td>"+
							  "<td>"+data.age+"</td>"+
							  "<td>"+sex+"</td>"+
							  "<td>"+data.className+"</td>").appendTo($("#findStuTable"));
					/* +
					  '<td><input type="button" value="更新" id="update"></td>'+
					  '<td><a href="#" id='+data.id+' class="delete">删除</a></td>' */
				});
				
				
				
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				alert("查找失败，找不到该学生！");
				/* alert(XMLHttpRequest.status);
				alert(XMLHttpRequest.readyState);
				alert(textStatus); */
			},
		})
	}
	//分页点击事件
	$("#preButton").click(function(){
		
		
		pageNum==1?1:pageNum--;
		findStudentInfo(pageNum,pageSize);
		
	});
	$("#nextButton").click(function(){
		
		pageNum==endPage?endPage:pageNum++;
		findStudentInfo(pageNum,pageSize);
	});
	//加载
	$("#submit").click(function(){
		findStudentInfo(pageNum,pageSize);
	});
	//end
});

</script>
</head>

	<body>
	<center>
		<p>	学生编号：<input type="text" name="fid" id="fid"/><br>
			学生姓名：<input type="text" name="stuId" id="fsname"/><br>
			班级名称：<input type="text" name="fclassName" id="fclassName"/><br>
		<input type="button" id="submit" value="查询" /></p>
		<table border="1" id="findStuTable">
			<tr id="tr1">
				<td>编号</td>
				<td>姓名</td>
				<td>年龄</td>
				<td>性别</td>
				<td>班级</td>
			</tr>
		</table>
		<input type="button" value="上一页" id="preButton"><input type="button" value="下一页" id="nextButton">
	</center>
	</body>
</html>
